<template>
	<vue-simplebar>
		<div class="max-w-screen-lg mx-auto">
			<div class="page-container">
				<div class="page-container-inner flex-auto">
					<div class="py-12">
						<div v-if="['loading', 'error'].indexOf(dataStatus) >= 0" class="text-center">
							<component-page-loading :status="dataStatus" @reload="getData"></component-page-loading>
						</div>
						<div v-else>
							<!--显示-->
							<div v-if="!dataEditStatus">
								<el-form label-width="180px" class="detail">
									
									<!--系统场控-->
									<el-divider>{{ $t('platform.config.rtpConfigTitle.rtp_period') }}</el-divider>
									<el-row>
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodInitGain')">
												{{ data.info.rtp_period.init.gain }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodInitCost')">
												{{ data.info.rtp_period.init.cost }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodRtpExpect')">
												{{ data.info.rtp_period.rtp_expect }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodResetTime')">
												{{ data.info.rtp_period.reset_time }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodAddTime')">
												{{ data.info.rtp_period.add_time }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodSubTime')">
												{{ data.info.rtp_period.sub_time }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodPeriodTime')">
												{{ data.info.rtp_period.period_time }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodLastDuration')">
												{{ data.info.rtp_period.last_duration }}
											</el-form-item>
										</el-col>
									</el-row>
									
									<!--系统个控-->
									<el-divider>{{ $t('platform.config.rtpConfigTitle.person_revise') }}</el-divider>
									<el-row>
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseInitGain')">
												{{ data.info.person_revise.init.gain }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseInitCost')">
												{{ data.info.person_revise.init.cost }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseAddRtp')">
												{{ data.info.person_revise.add_rtp }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseAddRtpRate')">
												{{ data.info.person_revise.add_rtp_rate }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseSubRtp')">
												{{ data.info.person_revise.sub_rtp }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseSubRtpRate')">
												{{ data.info.person_revise.sub_rtp_rate }}
											</el-form-item>
										</el-col>
									</el-row>
									
									<!--系统新手控制-->
									<el-divider>{{ $t('platform.config.rtpConfigTitle.person_revise_new') }}</el-divider>
									<el-row>
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personGainCondition')">
												{{ data.info.person_revise_new.gain_condition }}
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personCostCondition')">
												{{ data.info.person_revise_new.cost_condition }}
											</el-form-item>
										</el-col>
										
										<!--                    <el-col :md="12">-->
										<!--                      <el-form-item :label="$t('platform.config.rtpConfig.personCostNowCondition')">-->
										<!--                        {{ data.info.person_revise_new.cost_now_condition }}-->
										<!--                      </el-form-item>-->
										<!--                    </el-col>-->
									</el-row>
									
									<!--操作-->
									<el-form-item>
										<el-button @click="editData">{{ $t('action.edit') }}</el-button>
									</el-form-item>
								</el-form>
							</div>
							<!--编辑-->
							<div v-if="dataEditStatus">
								<el-form label-width="180px" :model="dataCache">
									
									<!--系统场控-->
									<el-divider>{{ $t('platform.config.rtpConfigTitle.rtp_period') }}</el-divider>
									<el-row>
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodInitGain')"
											              required
											              :error="Boolean(msg.errors[`info.rtp_period.init.gain`]) ? msg.errors[`info.rtp_period.init.gain`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.init.gain"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodInitCost')"
											              required
											              :error="Boolean(msg.errors[`info.rtp_period.init.cost`]) ? msg.errors[`info.rtp_period.init.cost`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.init.cost"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodRtpExpect')"
											              required
											              :error="Boolean(msg.errors[`info.rtp_period.rtp_expect`]) ? msg.errors[`info.rtp_period.rtp_expect`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.rtp_expect"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodResetTime')"
											              required
											              :error="Boolean(msg.errors[`info.rtp_period.reset_time`]) ? msg.errors[`info.rtp_period.reset_time`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.reset_time"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodAddTime')"
											              required
											              :error="Boolean(msg.errors[`info.rtp_period.add_time`]) ? msg.errors[`info.rtp_period.add_time`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.add_time"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodSubTime')"
											              required
											              :error="Boolean(msg.errors[`info.rtp_period.sub_time`]) ? msg.errors[`info.rtp_period.sub_time`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.sub_time"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodPeriodTime')"
											              :error="Boolean(msg.errors['info.rtp_period.period_time.0']) ? msg.errors['info.rtp_period.period_time.0'][0] : ''
                                                   || Boolean(msg.errors['info.rtp_period.period_time.1']) ? msg.errors['info.rtp_period.period_time.1'][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.period_time[0]"
												          type="number"></el-input>
												<el-input class="small" v-model.number="dataCache.info.rtp_period.period_time[1]"
												          type="number"></el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.rtpPeriodLastDuration')"
											              required
											              :error="Boolean(msg.errors[`info.rtp_period.last_duration`]) ? msg.errors[`info.rtp_period.last_duration`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.rtp_period.last_duration"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
									</el-row>
									
									
									<!--系统个控-->
									<el-divider>{{ $t('platform.config.rtpConfigTitle.person_revise') }}</el-divider>
									<el-row>
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseInitGain')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise.init.gain`]) ? msg.errors[`info.person_revise.init.gain`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise.init.gain"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseInitCost')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise.init.cost`]) ? msg.errors[`info.person_revise.init.cost`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise.init.cost"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseAddRtp')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise.add_rtp`]) ? msg.errors[`info.person_revise.add_rtp`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise.add_rtp"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseAddRtpRate')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise.add_rtp_rate`]) ? msg.errors[`info.person_revise.add_rtp_rate`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise.add_rtp_rate"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseSubRtp')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise.sub_rtp`]) ? msg.errors[`info.person_revise.sub_rtp`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise.sub_rtp"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personReviseSubRtpRate')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise.sub_rtp_rate`]) ? msg.errors[`info.person_revise.sub_rtp_rate`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise.sub_rtp_rate"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
									</el-row>
									
									<!--系统新手控制-->
									<el-divider>{{ $t('platform.config.rtpConfigTitle.person_revise_new') }}</el-divider>
									<el-row>
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personGainCondition')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise_new.gain_condition`]) ? msg.errors[`info.person_revise_new.gain_condition`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise_new.gain_condition"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										
										<el-col :md="12">
											<el-form-item :label="$t('platform.config.rtpConfig.personCostCondition')"
											              required
											              :error="Boolean(msg.errors[`info.person_revise_new.cost_condition`]) ? msg.errors[`info.person_revise_new.cost_condition`][0] : ''">
												<el-input class="small" v-model.number="dataCache.info.person_revise_new.cost_condition"
												          type="number">
												</el-input>
											</el-form-item>
										</el-col>
										
										<!--                    <el-col :md="12">-->
										<!--                      <el-form-item :label="$t('platform.config.rtpConfig.personCostNowCondition')"-->
										<!--                                    required-->
										<!--                                    :error="Boolean(msg.errors[`info.person_revise_new.cost_now_condition`]) ? msg.errors[`info.person_revise_new.cost_now_condition`][0] : ''">-->
										<!--                        <el-input class="small" v-model.number="dataCache.info.person_revise_new.cost_now_condition"-->
										<!--                                  type="number">-->
										<!--                        </el-input>-->
										<!--                      </el-form-item>-->
										<!--                    </el-col>-->
									</el-row>
									
									
									<!--操作-->
									<el-form-item>
										<el-button type="primary" @click="onSubmit">{{ $t('action.save') }}</el-button>
										<el-button @click="dataEditStatus = false">{{ $t('action.cancel') }}</el-button>
									</el-form-item>
								</el-form>
							</div>
						</div>
					
					
					</div>
				</div>
			</div>
		</div>
	</vue-simplebar>
</template>

<script>

export default {
	data() {
		return {
			dataStatus: 'dle',
			data: {
				info: {
					rtp_period: {
						init: {
							gain: null,
							cost: null
						},
						rtp_expect: null,
						reset_time: null,
						add_time: null,
						sub_time: null,
						period_time: [null, null],
						last_duration: null,
					},
					person_revise: {
						init: {
							gain: null,
							cost: null,
						},
						add_rtp: null,
						add_rtp_rate: null,
						sub_rtp: null,
						sub_rtp_rate: null,
					},
					person_revise_new: {
						gain_condition: null,
						cost_condition: null,
						// cost_now_condition: null
					}
				}
			},
			dataEditStatus: false,
			dataCache: {},
			msg: {
				code: 200,
				message: '',
				errors: {},
			},
			index: 1001,
		}
	},
	mounted() {
		// 获取数据
		this.getData();
	},
	methods: {
		getData() {
			this.dataStatus = 'loading';
			// 获取数据
			axios.get(`/game/config/rtpConfig/getData`).then((response) => {
				if (response.data.resp_msg.code == 200) {
					if (response.data.resp_data.info != null) {
						this.data = response.data.resp_data;
					}
					console.log(this.data)
					this.dataStatus = 'dle';
				} else {
					this.dataStatus = 'error';
				}
			})
		},
		initMsg() {
			this.msg.code = 200;
			this.msg.message = '';
			this.msg.errors = {};
		},
		editData() {
			// 重置验证
			this.initMsg();
			// 克隆数据
			this.dataCache = _.cloneDeep(this.data);
			// 编辑状态
			this.dataEditStatus = true;
		},
		onSubmit() {
			this.initMsg();
			// loading 状态 start
			let loading = this.$loading();
			// 保存数据
			axios.post(`/game/config/rtpConfig/save`, this.dataCache).then((response) => {
				// loading 状态 close
				loading.close();
				// 逻辑处理
				if (response.data.resp_msg.code == 200) {
					this.$message({
						type: 'success',
						message: this.$t('messages.succeeded', {status: this.$t('action.save')}),
						showClose: true
					});
					this.dataEditStatus = false;
					// 更新数据
					this.data = response.data.resp_data;
				} else if (_.includes([42000], response.data.resp_msg.code)) {
					this.$message({
						type: 'error',
						message: response.data.resp_msg.message,
						showClose: true
					});
					this.msg = response.data.resp_msg;
				} else {
					this.$message({
						type: 'error',
						dangerouslyUseHTMLString: true,
						message: this.$t('messages.failed', {status: this.$t('action.save')}) + `<div class="mt-2">${response.data.resp_msg.message}</div>`,
						showClose: true
					});
				}
			})
		},
	}
}
</script>

<style lang="scss">
.py-12 {
	padding-top: 0rem !important;
}
</style>
